<template>
    <el-container class="home_container">
        <!-- 头 -->
        <el-header>
            <div>
                <img class="logoImg" src="../assets/360.jpg"/>
                <span>我的后台管理系统</span>
            </div>
            <el-button type="info" @click="logout">退出</el-button></el-header>
        <!-- 主体内容 -->
        <el-container>
            <!-- 侧边栏 -->
            <!-- <el-aside :width="isCollapse? '64px':'200px'">
                <div class="toggle-button" @click="toggleCollapse">|||</div>
                <el-menu 
                    :router = 'true'
                    class="el-menu-vertical-demo"
                    background-color="#373d41"
                    text-color="#fff"
                    active-text-color= "#ffd04b"
                    :unique-opened= 'true'
                    :collapse= 'isCollapse'
                    :collapse-transition= 'false'
                    :default-active= 'activePath'
                    >
                <el-submenu :index="item.id + ''" v-for="item in menuList" :key="item.id">
                    <template slot="title">
                        <i :class="iconObj[item.id]"></i>
                        <span>{{item.permissionName}}</span>
                    </template>
                    <el-menu-item @click="saveNavState(child.permissionUrl)" :index="child.permissionUrl" v-for="child in item.children" :key="child.id">
                        <template slot="title">
                            <i class="el-icon-menu"></i>
                            <span>{{child.permissionName}}</span>
                        </template>
                    </el-menu-item>
                </el-submenu>
                </el-menu>
            </el-aside> -->
            <el-aside :width="isCollapse? '64px':'200px'">
                <div class="toggle-button" @click="toggleCollapse">|||</div>
                <el-menu 
                    :router = 'true'
                    class="el-menu-vertical-demo"
                    background-color="#373d41"
                    text-color="#fff"
                    active-text-color= "#ffd04b"
                    :unique-opened= 'true'
                    :collapse= 'isCollapse'
                    :collapse-transition= 'false'
                    :default-active= 'activePath'
                    >
                <el-submenu :index="1">
                    <template slot="title"><i class="el-icon-message"></i>导航一</template>
                    <el-menu-item-group>
                    <el-menu-item index="1-1">用户</el-menu-item>
                    <el-menu-item index="1-2">选项2</el-menu-item>
                    </el-menu-item-group>
                </el-submenu>
                </el-menu>
            </el-aside>
            <!-- 内容 -->
            <el-main>
                <!-- 路由占位符 -->
                <router-view></router-view>
            </el-main>
         </el-container>
    </el-container>
</template>

<script>
export default {

    data(){
        return{
            menuList:[],
            iconObj:{
                '1': 'iconfont icon-icon-test10',
                '4': 'iconfont icon-icon-test21',
                '7': 'iconfont icon-icon-test19',
                '8': 'iconfont icon-icon-test9',
                '9': 'iconfont icon-icon-test4'
            },
            isCollapse: false,
            activePath: ''
        }
    },
    created(){
        //获取菜单树
        this.getMemuList();
        this.activePath = window.sessionStorage.getItem("activePath");

    },

    methods:{
        //登出
        logout(){
            window.sessionStorage.clear();
            this.$router.push("/login")
        },

        //获取所有的菜单
        // async getMemuList(){
        //     const {data:res} = await this.$http.get("/Menu/findAllMenu");
        //     console.log(res)
        //     if(!res.code==200) return this.$message.error("失败");
        //     this.menuList = res.data.data;
        // },

        //点击折叠菜单
        toggleCollapse(){
            this.isCollapse = !this.isCollapse
        },

        //保存连接激活的状态
        saveNavState(url){
            window.sessionStorage.setItem("activePath",url);
            this.activePath = window.sessionStorage.getItem("activePath");
        }

    }
}
</script>

<style lang="less" scoped>


    .el-header{
        background-color: #373d41;
        display: flex;
        justify-content: space-between;
        padding-left: 10px;
        align-items: center;
        color: #eaedf1;
        font-size: 20px;
        >div{
            display: flex;
            align-items: center;
        }
    }

    .el-aside {
        background-color: #333744;
        .el-menu{
            border-right: 0px;
        } 
    }

    .el-main {
        background-color: #eaedf1;
    }

    .home_container{
        height: 100%;
    }

    .logoImg{
        height: 50px;
        width: 50px;
    }
    
    .iconfont{
        margin-right: 10px;
    }

    .toggle-button{
        background-color: #4A5064;
        font-size: 10px;
        line-height: 24px;
        color: #ffff;
        text-align: center;
        letter-spacing: 0.2em;
        cursor: pointer;
    }



</style>